import java.util.Stack;

/**
 * Created by zhangjinrui on 17/6/27.
 */

public class Solution173 {

    public static void main(String args[]){
        Solution173 s = new Solution173();
    }

    public class BSTIterator {

        public Stack<TreeNode> stack;
        public BSTIterator(TreeNode root) {
            stack = new Stack<>();
            TreeNode cur = root;
            while(cur != null){
                stack.push(cur);
                cur = cur.left;
            }
        }

        /** @return whether we have a next smallest number */
        public boolean hasNext() {
            return !stack.isEmpty();
        }

        /** @return the next smallest number */
        public int next() {
            TreeNode ret = stack.pop();
            TreeNode cur = ret.right;
            while(cur != null){
                stack.push(cur);
                cur = cur.left;
            }
            return ret.val;
        }
    }
}
